/*
 * SongForm.java
 *
 * Created on September 24, 2006, 8:16 PM
 */

package com.thornapple.setmanager;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

/**
 *
 * @author  Bill
 */
public class SongForm extends javax.swing.JPanel {
    
    private Song song;
    
    /** Creates new form SongForm */
    public SongForm() {
        initComponents();
        txtTab.getDocument().addDocumentListener(new DocumentListener() {
            public void changedUpdate(DocumentEvent e) {
            }
            public void insertUpdate(DocumentEvent e) {
                song.setTablature(txtTab.getText());
            }
            public void removeUpdate(DocumentEvent e) {
                song.setTablature(txtTab.getText());
            }
        });
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        lblSongTitle = new javax.swing.JLabel();
        lblArtist = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtTab = new javax.swing.JTextArea();

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblSongTitle.setText("Song Title");

        lblArtist.setText("Artist");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(lblSongTitle)
                    .add(lblArtist))
                .addContainerGap(354, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(lblSongTitle)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(lblArtist)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        txtTab.setColumns(20);
        txtTab.setRows(5);
        jScrollPane1.setViewportView(txtTab);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 405, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblArtist;
    private javax.swing.JLabel lblSongTitle;
    private javax.swing.JTextArea txtTab;
    // End of variables declaration//GEN-END:variables

    public void setSong(Song song) {
        //need to bind this stuff
        if (song == null)
            return;
        this.song = song;
        //System.out.println("tab:"+song.getTablature());
        this.txtTab.setText(song.getTablature());
        if (song.getArtist() != null)
            this.lblArtist.setText(song.getArtist().getName());
        this.lblSongTitle.setText(song.getName());
        this.txtTab.setCaretPosition(0);
    }

    public Song getSong() {
        song.setTablature(this.txtTab.getText());
        return song;
    }
    
}
